This article is for development with Visual Studio Code, a multi-platform source code editor developed by Microsoft. For development with "full" Visual Studio (Windows-only) IDE, see Getting Started with OPC Data Client under .NET 6+ using full IDE.
Open a command prompt.
Create a folder named Hello and navigate to the folder.
Type the following: dotnet new console. This command creates a project file (Hello.csproj) and a main program file (Program.cs).
Type the following: dotnet add package OpcLabs.OpcWizard. This command adds OPC Wizard package reference to the project file.
Type the following: code . (note the dot '.' as a parameter to the command.) Visual Studio Code starts and its window opens.
At this point, you might be asked "Required assets to build and debug are missing from 'vscode'. Add them?". If so, press the
button in the popup window.A notification will appear "There are unresolved dependencies from 'Hello.csproj'. Please execute the restore command to continue.". Press the
button in the popup window.In the Explorer window, click on the Program.cs file. The file opens in the code editor.
Add following code to the beginning of the Program.cs file:
In Program.cs, if there is a Main method, replace its body by the following code. If there is no Main method, just top-level statements, simply replace them all.
Select F5) from the menu, or press the corresponding button on the toolbar.
-> (This will build and launch the program. The server is now running. A firewall pop-up window may appear, asking you for consent with allowing the communication. Provide the consent as needed; allowing the communication on private networks is sufficient.
OPC UA clients can connect to the server's endpoint on "opc.tcp://localhost:48040/" . You can verify it using any OPC UA client; see further below for instructions.
After you are done, press Enter to exit the program.
When the OPC UA server is running, any OPC UA client can connect to it and read or subscribe to the value of the variable we have defined in the server. When the OPC UA client is on the same computer, it can connect to "opc.tcp://localhost:48040/" to access this server; otherwise, replace the "localhost" in the endpoint URL by the name of the computer (host) on your network.
If the OPC UA Local Discovery Server (LDS) is installed on the computer where the server is running, the server will automatically register itself with the LDS and will thus become discoverable by OPC UA clients through the LDS. For this to work, the LDS must either accept unauthenticated registrations, or be configured to trust the server. For more information, see OPC UA LDS Integration. The use of the LDS is optional.
If the OPC UA clients allows you to browse the address space of the server, the variable that we have defined is located directly under the Objects folder, and is named DataVariable1. Its node Id is:
If you have the Connectivity Explorer application (e.g. if you have installed OPC Wizard using the OPC Studio Setup program, or obtained the Connectivity Explorer separately e.g. through ClickOnce deployment), you can use it for verification of the created OPC UA server as follows:
If you have the OpcCmd utility (e.g. if you have installed OPC Wizard using the OPC Studio Setup program, or obtained the OpcCmd separately e.g. through ClickOnce deployment), you can use it for verification of the created OPC UA server as follows:
uaClient subscribe opc.tcp://localhost:48040/ nsu=http://opclabs.com/OpcUA/Custom/Objects;s=DataVariable1
For simplicity in configuration, the OPC UA server created in this Getting Started exposes an insecure endpoint, and allows OPC UA connections without application authentication. Any production OPC UA server should, at least by default, disable the insecure endpoint. For more information, see Securing OPC Wizard Servers.